import 'package:flutter/widgets.dart';

class AboutPageTranslation {
  static final delegate = _AboutPageTranslationDelegate();

  static AboutPageTranslation of(BuildContext context) {
    return Localizations.of(context, AboutPageTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get title {
    return _resolve(const {
      'ru': 'О приложении',
      'en': 'About',
    });
  }

  String get privacyPolicyTileTitle {
    return _resolve(const {
      'ru': 'Политика конфиденциальности',
      'en': 'Privacy policy',
    });
  }

  String get termsOfUseTileTitle {
    return _resolve(const {
      'ru': 'Условия использования',
      'en': 'Terms of use',
    });
  }
}

class _AboutPageTranslationDelegate extends LocalizationsDelegate<AboutPageTranslation> {
  @override
  bool isSupported(Locale locale) => const ['ru', 'en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<AboutPageTranslation> old) => false;

  @override
  Future<AboutPageTranslation> load(Locale locale) async {
    final translation = AboutPageTranslation();
    await translation.load(locale);
    return translation;
  }
}
